<!doctype html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>教学实训管理系统</title>

    <link rel="stylesheet" type="text/css" href="css/styles.css">
    <style type="text/css">
        body,td,th { font-family: "Source Sans Pro", sans-serif; }
        body { background-color: #ffffff; }
    </style>
</head>
<body>


<div class="wrapper">

    <div class="container">
        <h1>Welcome</h1>
        <form class="form">
            <input id="userName" type="text" placeholder="Username">
            <input id="userPass" type="password" placeholder="Password">
            <span id="tips"></span>
            <p style="padding: 10px"><a style="padding-left: 18%;padding-right: 18%" type="submit" id="login-button">Login</a></p>
        </form>
    </div>

    <ul class="bg-bubbles">
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>

</div>

<script src="assets/js/core/jquery.3.2.1.min.js"></script>
<script type="text/javascript">
    $('#login-button').click(function(event){
        var userName = $("#userName").val().replace(/(^\s+)|(\s+$)/g,"");
        var userPass = $("#userPass").val().replace(/(^\s+)|(\s+$)/g,"");
        if (userName == ""){
            $("#tips").html("请输入用户名")
            return;
        }if (userPass == ""){
            $("#tips").html("请输入密码")
            return;
        }
        var param = {
            userName:userName,
            userPwd:userPass
        }
        $.ajax({
            url:'/oa/t-user/login',
            type:"POST",
            data:JSON.stringify(param),
            dataType: "json",
            contentType: 'application/json; charset=UTF-8',
            success:function(data){
                console.log(data)
                if (data.code == 200) {
                    sessionStorage.setItem("token",data.data.token);
                    sessionStorage.setItem("userName",data.data.userName)
                    sessionStorage.setItem("id",data.data.id);
                    sessionStorage.setItem("userPwd",data.data.userPwd);
                    $("#tips").html("")
                    event.preventDefault();
                    $('form').fadeOut(500);
                    $('.wrapper').addClass('form-success');
                    setTimeout(jump, 500)
                }else {
                    $("#tips").html(data.msg)
                    $("#tips").val("")
                    return;
                }
            }
        })

    });
    function jump() {
        window.location.href = 'index.html'
    }
</script>

</body>
</html>